package org.bt.common.validator.size;

import org.bt.common.validator.aspect.Size;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author tongw
 */
public class SizeValidatorForArraysOfFloat extends SizeValidatorForArraysOfPrimitives
        implements ConstraintValidator<Size, float[]> {

    /**
     * Checks the number of entries in an array.
     *
     * @param array                      The array to validate.
     * @param constraintValidatorContext context in which the constraint is evaluated.
     * @return Returns {@code true} if the array is {@code null} or the number of entries in
     * {@code array} is between the specified {@code min} and {@code max} values (inclusive),
     * {@code false} otherwise.
     */
    @Override
    public boolean isValid(float[] array, ConstraintValidatorContext constraintValidatorContext) {
        if (array == null) {
            return true;
        }
        return array.length >= min && array.length <= max;
    }
}
